package com.mark.org.controller;

import com.mark.basic.util.AjaxResult;
import com.mark.basic.util.PageList;
import com.mark.org.domain.Detail;
import com.mark.org.query.DetailQuery;
import com.mark.org.query.TypeQuery;
import com.mark.org.service.IDetailService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
@Api(tags = "数据字典明细接口",description = "数据字典明细接口详细描述")
public class DetailController {
    @Autowired
    private IDetailService detailService;
    @GetMapping("/{id}")
    /**
     * 查询单个数据
     */
    public Detail queryById(@PathVariable("id") Long id){
        return detailService.listById(id);
    }
    @GetMapping
    /**
     * 查询所有数据
     */
    public List<Detail> queryAll(){
        return detailService.listAll();
    }
    @DeleteMapping("/{id}")
    /**
     * 删除数据
     */
    public AjaxResult del(@PathVariable("id") Long id){
        try {
            detailService.del(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMassage("系统繁忙,请稍后操作！！！").setSuccess(false);
        }
    }
    @PutMapping
    /**
     * 添加或修改数据
     */
    public AjaxResult addOrUpdate(@RequestBody Detail detail){
        System.err.println(detail);
        System.err.println(detail.getId());
        if (detail.getId() == null) {
            detailService.add(detail);
        } else {
            detailService.update(detail);
        }
        return AjaxResult.me();
    }
    /**
     * 分页查询
     */
    @PostMapping
    public PageList<Detail> queryPage(@RequestBody TypeQuery query){
        PageList<Detail> aa = detailService.queryPage(query);
        return aa;
    }

    /**
     * 批量删除
     */
    @PatchMapping
    public AjaxResult batchRemove(@RequestBody List<Long> ids){
        try {
            System.err.println(ids);
            detailService.batchRemove(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMassage("系统繁忙,请稍后操作！！！").setSuccess(false);
        }
    }
}